/*
 * Copyright 2006 Robert Burrell Donkin
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */ 
package rat.element;

import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;


/**
 * A note is content associated with the release 
 * rather than the content of the release.
 * Examples: README.txt, LICENSE, NOTICE
 */
public class NoteElement extends AbstractElement {

    private static final String[] NOTE_FILE_NAMES = {
	"NOTICE", "LICENSE",
        "LICENSE.txt", "NOTICE.TXT", 
        "INSTALL", "INSTALL.TXT",
        "README", "README.TXT", 
        "NEWS", "NEWS.TXT",
        "AUTHOR", "AUTHOR.TXT",
        "AUTHORS", "AUTHORS.txt",
        "CHANGELOG", "CHANGELOG.TXT",
        "DISCLAIMER", "DISCLAIMER.TXT",
        "KEYS", "KEYS.TXT",
        "RELEASE-NOTES", "RELEASE-NOTES.TXT",
        "RELEASE_NOTES", "RELEASE_NOTES.TXT",
        "UPGRADE", "UPGRADE.TXT",
        "STATUS", "STATUS.TXT",
        "THIRD_PARTY_NOTICES", "THIRD_PARTY_NOTICES.TXT",
        "COPYRIGHT", "COPYRIGHT.TXT",
        "BUILDING", "BUILDING.TXT",
    };

    private static final String[] NOTE_FILE_EXTENSIONS = {
        "LICENSE", "LICENSE.TXT",
        "NOTICE", "NOTICE.TXT",
    };

	public NoteElement(File file) {
		super(file);
	}

	public NoteElement(String name) {
            super(name, null);
	}

	public void accept(IElementVisitor visitor) {
		visitor.visit(this);
	}
	
	public String toString() {
		return "  N     " + getName();
	}

    /**
     * Is a file by that name a note file?
     */
    public static final boolean isNote(final String name) {
        if (name == null) {return false;}

        List l = Arrays.asList(NOTE_FILE_NAMES);
        String nameToUpper = name.toUpperCase(Locale.US);
        boolean result = l.contains(name) || l.contains(nameToUpper);
        for (int i = 0; !result && i < NOTE_FILE_EXTENSIONS.length; i++) {
            result = nameToUpper.endsWith("." + NOTE_FILE_EXTENSIONS[i]);
        }
        return result;
    }
}
